# import numpy as np
import matplotlib.pyplot as plt
# import matplotlib
from .DataAnalyse import DataAnalyse


class DataVisualization:

    def __init__(self, da: DataAnalyse):
        self.da = da

    def ta_display(self, sheet, row, col, start=1997, end=2015):
        x, y = self.da.time_analyse(sheet, row, col, start, end)
        plt.plot(x, y)
        plt.xlabel("Date")
        plt.ylabel("CO2/Mt")
        plt.title(f"TimeAnalyse\n{sheet}, {row}, {col}")
        plt.show()

    def sa_display(self, year, _type, industry='Sum', province='', plot_type="bar"):
        x, y = self.da.space_analyse(year, _type, industry, province)
        if plot_type == "bar":
            plt.tick_params(axis='y', labelsize=6)
            plt.barh(x, y)
            plt.xlabel("province")
            plt.ylabel("CO2/Mt")
        elif plot_type == "pie":
            if sum(y) == 0:
                raise ZeroDivisionError(f"Year: {year}\nSource: {_type}\nIndustry: {industry}")
            plt.pie(y, labels=x, autopct='%1.1f%%', shadow=False)
        plt.title(f"SpaceAnalyse\n{year}, {_type}, {industry}")
        plt.show()
